import { createSSRApp } from 'vue'
import App from './App.vue'
import * as Pinia from 'pinia'
import { createUnistorage } from 'pinia-plugin-unistorage'
import { setupRouteGuard } from './utils/guard'
import uviewPlus from 'uview-plus'
import '@/styles/common.scss'
App.mpType = 'app'
export function createApp() {
  const app = createSSRApp(App)
  const store = Pinia.createPinia()
  store.use(createUnistorage())
  app.use(store)
  app.use(uviewPlus)
  // 延迟设置路由守卫，确保 store 已经初始化
  setTimeout(() => {
    setupRouteGuard()
  }, 0)

  return {
    app,
    Pinia,
  }
}
